# Contributor: Duncan Bellamy <dunk@denkimushi.com>
# Maintainer: Duncan Bellamy <dunk@denkimushi.com>
# based on arch linux PKGBUILD
pkgname=apache-arrow
pkgver=8.0.0
pkgrel=4
pkgdesc="multi-language toolbox for accelerated data interchange and in-memory processing"
url="https://arrow.apache.org/"
arch="all !s390x !riscv64" # missing glog-dev, thrift
license="Apache-2.0"
makedepends="
	boost-dev
	brotli-dev
	bzip2-dev
	c-ares-dev
	cmake
	glog-dev
	grpc-dev
	gtest-dev
	lz4-dev
	openssl-dev
	protobuf-dev
	py3-numpy-dev
	python3-dev
	rapidjson-dev
	re2-dev
	samurai
	snappy-dev
	thrift-dev
	utf8proc-dev
	zlib-dev
	zstd-dev
	"
checkdepends="bash grep gzip perl python3 tzdata"
subpackages="$pkgname-static $pkgname-dev $pkgname-tools $pkgname-doc"
_arrowsha="83ada4ec0f2cfe36f4168628d7f470e6199e663a"
_parquetsha="acd375eb86a81cd856476fca0f52ba6036a067ff"
source="https://downloads.apache.org/arrow/arrow-$pkgver/apache-arrow-$pkgver.tar.gz
	https://github.com/apache/arrow-testing/archive/$_arrowsha.zip
	https://github.com/apache/parquet-testing/archive/$_parquetsha.zip
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	case "$CARCH" in
		armhf|armv7) _SIMD="NONE" ;;
		*) _SIMD="DEFAULT" ;;
	esac
	cmake -B build \
		-G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=Release \
		-DARROW_DEPENDENCY_SOURCE=SYSTEM \
		-DARROW_SIMD_LEVEL="$_SIMD" \
		-DARROW_BUILD_TESTS=ON \
		-DARROW_COMPUTE=ON \
		-DARROW_FLIGHT=ON \
		-DARROW_GANDIVA=OFF \
		-DARROW_HDFS=ON \
		-DARROW_IPC=ON \
		-DARROW_JEMALLOC=OFF \
		-DARROW_ORC=OFF \
		-DARROW_PARQUET=ON \
		-DARROW_PLASMA=ON \
		-DARROW_PYTHON=ON \
		-DARROW_TENSORFLOW=ON \
		-DARROW_USE_GLOG=ON \
		-DARROW_WITH_BROTLI=ON \
		-DARROW_WITH_BZ2=ON \
		-DARROW_WITH_LZ4=ON \
		-DARROW_WITH_SNAPPY=ON \
		-DARROW_WITH_ZLIB=ON \
		-DARROW_WITH_ZSTD=ON \
		-DPARQUET_REQUIRE_ENCRYPTION=ON \
		-S cpp \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

check() {
	cd build
	export PARQUET_TEST_DATA="$srcdir/parquet-testing-$_parquetsha/data"
	export ARROW_TEST_DATA="$srcdir/arrow-testing-$_arrowsha/data"
	# exclude broken tests
	PYTHON=python3 ctest --output-on-failure -E "arrow-buffer-test|arrow-misc-test|\
arrow-utility-test|arrow-csv-test|arrow-compute-aggregate-test|arrow-flight-test|arrow-compute-scalar-test|\
arrow-dataset-file-ipc-test|arrow-dataset-scanner-test"
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	find "$pkgdir"/usr/lib/ -name '*testing*' -delete
}

tools() {
	pkgdesc="$pkgdesc (extra tools)"
	amove usr/bin/plasma-store-server
}

sha512sums="
8280ce775c05296e33a292241c976caee2bddda7da396ef3c5da700347cb616a932475140139a5e96027781e71f66466e27fcf6423440bf720fbc83faabf0f3d  apache-arrow-8.0.0.tar.gz
7d3c3678f69e4a244a1f8fdc4e509e29f3c21f8a8e38e9c9e3188dad0297a964201157853abd57bad75df698ab9b005ad0fca12c2965bbc4a25ccb5fd19311bb  83ada4ec0f2cfe36f4168628d7f470e6199e663a.zip
b3af78d5045ee3a224cafcd6246acf5b347187972b8ab50d55e6bbf4120ca06a55a8f73bec0901ed279c0c2059e3b1e3b12bba68a8c4f3bb5a7f13d1766e4f13  acd375eb86a81cd856476fca0f52ba6036a067ff.zip
"
